package per.com.controller.portal;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import per.com.bean.Report;
import per.com.bean.User;
import per.com.common.Const;
import per.com.common.ServerResponse;
import per.com.dao.PcUsersDao;
import per.com.service.IReportService;
import per.com.vo.ReportDetailVo;

import javax.servlet.http.HttpSession;

/**
 * @author zxy
 */
@Controller
@RequestMapping(value = "/report/")
@ResponseBody
public class ReportController {

    @Autowired
    private IReportService iReportService;

    @Autowired
    private PcUsersDao pcUsersDao;

    /**
     * 用户对其他用户进行举报
     * @param report
     * @return
     */
    @RequestMapping(value = "add_report" , method = RequestMethod.POST)
    public ServerResponse<ReportDetailVo> addReport(Report report){

        User user = pcUsersDao.selectByPrimaryKey(report.getReportedId());
        return iReportService.addReport(report.getUserId() , report.getReportReason() , user.getUsername());
    }

    /**
     * 用户获取到其举报某人的举报详情
     * @param id
     * @return
     */
    @RequestMapping(value = "report_detail" , method = RequestMethod.POST)
    public ServerResponse<ReportDetailVo> watchReportDetail(String id){

        return iReportService.findReportDetail(id);
    }

    /**
     * 用户获取到其举报列表，列表中包括其举报的所有人
     * @param pageNum
     * @param pageSize
     * @return
     */
    public ServerResponse<PageInfo> findList(@RequestParam(value = "pageNum" , defaultValue = "1") int pageNum ,
                                             @RequestParam(value = "pageSize" , defaultValue = "10") int pageSize,
                                             HttpSession session){

        User user = (User) session.getAttribute(Const.CURRENT_USER);
        return iReportService.findOneReport(user.getUid() , pageNum , pageSize);
    }


}
